package lexerPackage;

public class DFA implements IDFA {
	public final int START = 0;
	public final int ERROR = 1;
	public final int EOF = 2;
	public final int ID = 3;
	public final int INT = 4;
	public final int DATE = 5;
	public final int WS = 6;
	public final int COLON = 7;

	public DFA() {

	}

	@Override
	public int initial() {
		isStop(START);
		return START;
	}

	@Override
	public int trans(int state, int symbol) {
		char symbolChar = (char) symbol; // Punkt und Komma behandeln!!!
		if (state == START) {
			if (Character.isLetter(symbolChar))
				return ID;
			else if (Character.isDigit(symbolChar))
				return INT;
			else if (Character.isWhitespace(symbolChar))
				return WS;
			else
				return EOF;
		} else if (state == ID) {
			if (Character.isLetter(symbolChar))
				return ID;
			else if (String.valueOf(symbolChar).matches("\\p{Punct}")) //TODO
				return WS;
			else if (symbol == -1)
				return EOF;
			else
				return ERROR;
		} else if (state == INT) {
			if (Character.isDigit(symbolChar))
				return INT;
			else if (symbol == -1)
				return EOF;
			else
				return ERROR;
		} else if (state == WS) {
			if (symbol == -1)
				return EOF;
			else
				return ERROR;
		} else
			return EOF;

	}

	@Override
	public boolean isFinal(int state) {
		return (state == EOF);
		
	}

	@Override
	public boolean isStop(int state) {
		switch (state) {
		case ERROR:
			return true;
		case EOF:
			return true;
		default:
			return false;
		}
	}

	@Override
	public TokenClassEnum getTokenClasses(int state) {
		switch (state) {
		case START:
			return TokenClassEnum.START;
		case ERROR:
			return TokenClassEnum.ERROR;
		case EOF:
			return TokenClassEnum.EOF;
		case ID:
			return TokenClassEnum.ID;
		case INT:
			return TokenClassEnum.INT;
		case DATE:
			return TokenClassEnum.DATE;
		case WS:
			return TokenClassEnum.WS;
		case COLON:
			return TokenClassEnum.COLON;
		default:
			return TokenClassEnum.ERROR;
		}
	}

}
